import { observable, action, toJS } from 'mobx';
import ListBaseStore from './ListBaseStore';
import * as SpaceAPI from '../apis/space';
import objectAssign from 'object-assign';
import moment from 'moment';
import { WeaForm, WeaTableNew } from 'comsMobx';

export default class Space extends ListBaseStore {
	@observable currentuserid='';

	 @action
	 doLoading(params = {}) {
		 this.showLoading(true);
	     SpaceAPI.getCurrentUserid(params).then((data) => {
	    	 this.currentuserid = data.currentuserid;
	     });

	     // 调用API
         SpaceAPI.getDatas(params).then((data) => {
        	 const sessionkey = data.sessionkey;
			 this.sessionkey = sessionkey;
			 this.tableStore.getDatas(sessionkey);
         });
         this.showLoading(false);
	}


	 @action initBatchForm() {
		 	SpaceAPI.getBatchSetCondition().then(action((data) => {
		 		this.conditioninfo = data.conditioninfo;
		 		this.reinitializeForm(this.conditioninfo);
		 	}));
	 }
	 @action initSingleSetForm(params = {}) {
		 SpaceAPI.getBatchSetCondition(params).then(action((data) => {
		 		this.conditioninfo = data.conditioninfo;
		 		this.reinitializeForm(this.conditioninfo);
		 }));
	 }

	 @action saveOrUpdateSpace(params = {}) {
		this.showLoading(true);
		SpaceAPI.saveOrUpdateSpace(params).then(() => {
			this.doLoading();
			this.showLoading(false);
		});
	}
}
